package org.apache.james.mime4j.field;

import java.util.Collections;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.james.mime4j.field.contenttype.parser.ParseException;

public class ContentTypeField extends Field
{
  public static final String PARAM_BOUNDARY = "boundary";
  public static final String PARAM_CHARSET = "charset";
  public static final String TYPE_MESSAGE_RFC822 = "message/rfc822";
  public static final String TYPE_MULTIPART_DIGEST = "multipart/digest";
  public static final String TYPE_MULTIPART_PREFIX = "multipart/";
  public static final String TYPE_TEXT_PLAIN = "text/plain";
  static Class class$org$apache$james$mime4j$field$ContentTypeField$Parser;
  private String mimeType = "";
  private Map parameters = null;
  private ParseException parseException;

  protected ContentTypeField(String paramString1, String paramString2, String paramString3, String paramString4, Map paramMap, ParseException paramParseException)
  {
    super(paramString1, paramString2, paramString3);
    this.mimeType = paramString4;
    this.parameters = paramMap;
    this.parseException = paramParseException;
  }

  static Class class$(String paramString)
  {
    Class localClass;
    try
    {
      localClass = Class.forName(paramString);
      return localClass;
    }
    catch (ClassNotFoundException localClassNotFoundException)
    {
      throw new NoClassDefFoundError().initCause(localClassNotFoundException);
    }
  }

  public static String getCharset(ContentTypeField paramContentTypeField)
  {
    String str;
    if ((paramContentTypeField != null) && (paramContentTypeField.getCharset() != null) && (paramContentTypeField.getCharset().length() > 0))
      str = paramContentTypeField.getCharset();
    while (true)
    {
      return str;
      str = "us-ascii";
    }
  }

  public static String getMimeType(ContentTypeField paramContentTypeField1, ContentTypeField paramContentTypeField2)
  {
    String str;
    if ((paramContentTypeField1 == null) || (paramContentTypeField1.getMimeType().length() == 0) || ((paramContentTypeField1.isMultipart()) && (paramContentTypeField1.getBoundary() == null)))
      if ((paramContentTypeField2 != null) && (paramContentTypeField2.isMimeType("multipart/digest")))
        str = "message/rfc822";
    while (true)
    {
      while (true)
      {
        return str;
        str = "text/plain";
      }
      str = paramContentTypeField1.getMimeType();
    }
  }

  public String getBoundary()
  {
    return getParameter("boundary");
  }

  public String getCharset()
  {
    return getParameter("charset");
  }

  public String getMimeType()
  {
    return this.mimeType;
  }

  public String getParameter(String paramString)
  {
    String str;
    if (this.parameters != null)
      str = (String)this.parameters.get(paramString.toLowerCase());
    while (true)
    {
      return str;
      str = null;
    }
  }

  public Map getParameters()
  {
    Map localMap;
    if (this.parameters != null)
      localMap = Collections.unmodifiableMap(this.parameters);
    while (true)
    {
      return localMap;
      localMap = Collections.EMPTY_MAP;
    }
  }

  public ParseException getParseException()
  {
    return this.parseException;
  }

  public boolean isMimeType(String paramString)
  {
    return this.mimeType.equalsIgnoreCase(paramString);
  }

  public boolean isMultipart()
  {
    return this.mimeType.startsWith("multipart/");
  }

  public static class Parser
  implements FieldParser
  {
    private static Log log;

    static
    {
      Class localClass;
      if (ContentTypeField.class$org$apache$james$mime4j$field$ContentTypeField$Parser == null)
      {
        localClass = ContentTypeField.class$("org.apache.james.mime4j.field.ContentTypeField$Parser");
        ContentTypeField.class$org$apache$james$mime4j$field$ContentTypeField$Parser = localClass;
      }
      while (true)
      {
        log = LogFactory.getLog(localClass);
        return;
        localClass = ContentTypeField.class$org$apache$james$mime4j$field$ContentTypeField$Parser;
      }
    }

    // ERROR //
    public Field parse(String paramString1, String paramString2, String paramString3)
    {
      // Byte code:
      //   0: aconst_null
      //   1: astore 4
      //   3: ldc 44
      //   5: astore 5
      //   7: aconst_null
      //   8: astore 6
      //   10: new 46	java/io/StringReader
      //   13: dup
      //   14: aload_2
      //   15: invokespecial 49	java/io/StringReader:<init>	(Ljava/lang/String;)V
      //   18: astore 7
      //   20: new 51	org/apache/james/mime4j/field/contenttype/parser/ContentTypeParser
      //   23: dup
      //   24: aload 7
      //   26: invokespecial 54	org/apache/james/mime4j/field/contenttype/parser/ContentTypeParser:<init>	(Ljava/io/Reader;)V
      //   29: astore 8
      //   31: aload 8
      //   33: invokevirtual 57	org/apache/james/mime4j/field/contenttype/parser/ContentTypeParser:parseAll	()V
      //   36: aload 8
      //   38: invokevirtual 61	org/apache/james/mime4j/field/contenttype/parser/ContentTypeParser:getType	()Ljava/lang/String;
      //   41: astore 11
      //   43: aload 8
      //   45: invokevirtual 64	org/apache/james/mime4j/field/contenttype/parser/ContentTypeParser:getSubType	()Ljava/lang/String;
      //   48: astore 12
      //   50: aload 11
      //   52: ifnull +291 -> 343
      //   55: aload 12
      //   57: ifnull +286 -> 343
      //   60: new 66	java/lang/StringBuffer
      //   63: dup
      //   64: invokespecial 67	java/lang/StringBuffer:<init>	()V
      //   67: aload 11
      //   69: invokevirtual 71	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
      //   72: ldc 73
      //   74: invokevirtual 71	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
      //   77: aload 8
      //   79: invokevirtual 64	org/apache/james/mime4j/field/contenttype/parser/ContentTypeParser:getSubType	()Ljava/lang/String;
      //   82: invokevirtual 71	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
      //   85: invokevirtual 76	java/lang/StringBuffer:toString	()Ljava/lang/String;
      //   88: invokevirtual 81	java/lang/String:toLowerCase	()Ljava/lang/String;
      //   91: astore 5
      //   93: aload 8
      //   95: invokevirtual 85	org/apache/james/mime4j/field/contenttype/parser/ContentTypeParser:getParamNames	()Ljava/util/ArrayList;
      //   98: astore 13
      //   100: aload 8
      //   102: invokevirtual 88	org/apache/james/mime4j/field/contenttype/parser/ContentTypeParser:getParamValues	()Ljava/util/ArrayList;
      //   105: astore 14
      //   107: aload 13
      //   109: ifnull +234 -> 343
      //   112: aload 14
      //   114: ifnull +229 -> 343
      //   117: iconst_0
      //   118: istore 15
      //   120: aconst_null
      //   121: astore 16
      //   123: iload 15
      //   125: aload 13
      //   127: invokevirtual 94	java/util/ArrayList:size	()I
      //   130: if_icmpge +246 -> 376
      //   133: iload 15
      //   135: aload 14
      //   137: invokevirtual 94	java/util/ArrayList:size	()I
      //   140: if_icmpge +236 -> 376
      //   143: aload 16
      //   145: ifnonnull +224 -> 369
      //   148: new 96	java/util/HashMap
      //   151: dup
      //   152: dconst_1
      //   153: ldc2_w 97
      //   156: aload 13
      //   158: invokevirtual 94	java/util/ArrayList:size	()I
      //   161: i2d
      //   162: dmul
      //   163: dadd
      //   164: d2i
      //   165: invokespecial 101	java/util/HashMap:<init>	(I)V
      //   168: astore 6
      //   170: aload 6
      //   172: aload 13
      //   174: iload 15
      //   176: invokevirtual 105	java/util/ArrayList:get	(I)Ljava/lang/Object;
      //   179: checkcast 78	java/lang/String
      //   182: invokevirtual 81	java/lang/String:toLowerCase	()Ljava/lang/String;
      //   185: aload 14
      //   187: iload 15
      //   189: invokevirtual 105	java/util/ArrayList:get	(I)Ljava/lang/Object;
      //   192: checkcast 78	java/lang/String
      //   195: invokeinterface 111 3 0
      //   200: pop
      //   201: iinc 15 1
      //   204: aload 6
      //   206: astore 16
      //   208: goto -85 -> 123
      //   211: astore 19
      //   213: getstatic 31	org/apache/james/mime4j/field/ContentTypeField$Parser:log	Lorg/apache/commons/logging/Log;
      //   216: invokeinterface 117 1 0
      //   221: ifeq +43 -> 264
      //   224: getstatic 31	org/apache/james/mime4j/field/ContentTypeField$Parser:log	Lorg/apache/commons/logging/Log;
      //   227: new 66	java/lang/StringBuffer
      //   230: dup
      //   231: invokespecial 67	java/lang/StringBuffer:<init>	()V
      //   234: ldc 119
      //   236: invokevirtual 71	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
      //   239: aload_2
      //   240: invokevirtual 71	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
      //   243: ldc 121
      //   245: invokevirtual 71	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
      //   248: aload 19
      //   250: invokevirtual 124	org/apache/james/mime4j/field/contenttype/parser/ParseException:getMessage	()Ljava/lang/String;
      //   253: invokevirtual 71	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
      //   256: invokevirtual 76	java/lang/StringBuffer:toString	()Ljava/lang/String;
      //   259: invokeinterface 128 2 0
      //   264: aload 19
      //   266: astore 4
      //   268: goto -232 -> 36
      //   271: astore 9
      //   273: getstatic 31	org/apache/james/mime4j/field/ContentTypeField$Parser:log	Lorg/apache/commons/logging/Log;
      //   276: invokeinterface 117 1 0
      //   281: ifeq +43 -> 324
      //   284: getstatic 31	org/apache/james/mime4j/field/ContentTypeField$Parser:log	Lorg/apache/commons/logging/Log;
      //   287: new 66	java/lang/StringBuffer
      //   290: dup
      //   291: invokespecial 67	java/lang/StringBuffer:<init>	()V
      //   294: ldc 119
      //   296: invokevirtual 71	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
      //   299: aload_2
      //   300: invokevirtual 71	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
      //   303: ldc 121
      //   305: invokevirtual 71	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
      //   308: aload 9
      //   310: invokevirtual 129	org/apache/james/mime4j/field/contenttype/parser/TokenMgrError:getMessage	()Ljava/lang/String;
      //   313: invokevirtual 71	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
      //   316: invokevirtual 76	java/lang/StringBuffer:toString	()Ljava/lang/String;
      //   319: invokeinterface 128 2 0
      //   324: new 38	org/apache/james/mime4j/field/contenttype/parser/ParseException
      //   327: dup
      //   328: aload 9
      //   330: invokevirtual 129	org/apache/james/mime4j/field/contenttype/parser/TokenMgrError:getMessage	()Ljava/lang/String;
      //   333: invokespecial 130	org/apache/james/mime4j/field/contenttype/parser/ParseException:<init>	(Ljava/lang/String;)V
      //   336: astore 4
      //   338: goto -302 -> 36
      //   341: astore 10
      //   343: new 8	org/apache/james/mime4j/field/ContentTypeField
      //   346: dup
      //   347: aload_1
      //   348: aload_2
      //   349: aload_3
      //   350: aload 5
      //   352: aload 6
      //   354: aload 4
      //   356: invokespecial 133	org/apache/james/mime4j/field/ContentTypeField:<init>	(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Lorg/apache/james/mime4j/field/contenttype/parser/ParseException;)V
      //   359: areturn
      //   360: astore 17
      //   362: aload 16
      //   364: astore 6
      //   366: goto -23 -> 343
      //   369: aload 16
      //   371: astore 6
      //   373: goto -203 -> 170
      //   376: aload 16
      //   378: astore 6
      //   380: goto -37 -> 343
      //
      // Exception table:
      //   from	to	target	type
      //   31	36	211	org/apache/james/mime4j/field/contenttype/parser/ParseException
      //   31	36	271	org/apache/james/mime4j/field/contenttype/parser/TokenMgrError
      //   36	107	341	java/lang/NullPointerException
      //   170	201	341	java/lang/NullPointerException
      //   123	170	360	java/lang/NullPointerException
    }
  }
}